#!/usr/bin/perl

use Modern::Perl;
use Test::More tests => 8;
use File::Slurp;
use Log::Log4perl qw( :easy );

require AEF::MEFProcessor;

Log::Log4perl->easy_init($INFO);

my $processor = AEF::MEFProcessor->new(moduleName => 'Test');

is($processor->TypeMap(0x20), "Z*", "Checking format string for module name");
is($processor->TypeMap(0x1), undef, "Checking get undef for other types");
is($processor->RequireDataForType(0x20), 1, "Checking we require module names");
is($processor->RequireDataForType(0x1), 0, "Checking we don't require anything else");
$processor->ProcessBlock(0x20, "Wrong", 1, 5);
my $header = pack('vVvZ*', 1, 0x1b, 0x280, 
						'CA-VO Module Export File');
is($processor->mefData, $header, "Checking we haven't stored the wrong module");
$processor->ProcessBlock(0x20, "Test", 1, 5);
my $expected = $header . pack('vVZ*', 0x20, 5, "Test");
is($processor->mefData, $expected, "Checking we have module name as data");
my $data = pack('Z*', 'Test');
$processor->ProcessBlock(0x1, $data, 1, 5);
$expected .= pack('vVZ*', 0x1, 5, "Test");
is($processor->mefData, $expected, "Checking we have the right data");
$processor->ProcessBlock(0x20, 'Next', 1, 4);
my $footer = pack('vV', 0xffff, 0);
is($processor->mefData, $expected . $footer, "Checking we have EOF");

# FIXME: test for module at EOF.


